package com.atguigu.sparktuning.cache_01

import com.atguigu.sparktuning.bean.CoursePay
import com.atguigu.sparktuning.utils.InitUtil
import org.apache.spark.SparkConf
import org.apache.spark.sql.{Dataset, SparkSession}
import org.apache.spark.storage.StorageLevel

/**
  * @Author  Zhongxu.Zhao
  * @ClassName DatasetCacheSerDemo
  * @Date 2021/12/13 23:26
  * @Desc: TODO
 **/
object DatasetCacheSerDemo {
  def main(args: Array[String]): Unit = {
    val sparkconf: SparkConf = new SparkConf().setAppName(this.getClass.getName).setMaster("local")
    val spark: SparkSession = InitUtil.initSparkSession(sparkconf)
    import  spark.implicits._
    val result: Dataset[CoursePay] = spark.sql("select * from sparktuning.course_pay ").as[CoursePay]
    result.persist(StorageLevel.MEMORY_AND_DISK_SER)

    result.foreachPartition((p:Iterator[CoursePay]) => p.foreach(item => println(item.orderid)))
    while(true){

    }

  }

}
